import {ConfigDataEntity} from "../../generate/entitas";
import excelConfig from "../../ExcelConfig";
import MethodInfo from "../MethodInfo";
import * as path from "path";
import * as fs from "fs";
export class BaseCodeGenerator{
	className : string
	dirPath : string
	makoPath : string
	outPath : string
	tempOutPath :string
	tempScriptPath : string
	tempDataPath : string
	suffix : string
	headData : Map<any, any>
	constructor() {
	}

	init(){
		this.headData = new Map()
		this.className = this.constructor.name
		this.makoPath = this.dirPath + "/template"
		this.tempOutPath = excelConfig.tempProjectRoot  + this.className + "/"
		this.tempScriptPath = path.join(this.tempOutPath, "Script")
		this.tempDataPath = path.join(this.tempOutPath, "Data")
		this.checkTempPath()
		this.onInit()
	}

	onInit(){

	}

	checkTempPath(){
		if (fs.existsSync(this.tempOutPath)){
			fs.rmdirSync(this.tempOutPath, {
				recursive: true  //是否递归,默认false
			})
		}
		fs.mkdirSync(this.tempOutPath, {
			recursive: true  //是否递归,默认false
		})
		fs.mkdirSync(this.tempScriptPath, {
			recursive: true  //是否递归,默认false
		})
		fs.mkdirSync(this.tempDataPath, {
			recursive: true  //是否递归,默认false
		})
	}

	//region  生成数据
	beforeGenData(entity : ConfigDataEntity){
		this.onBeforeGenData(entity)
	}

	afterGenData(entity : ConfigDataEntity){
		this.onAfterGenData(entity)
	}

	startGeData(entity : ConfigDataEntity){
		this.onStartGenData(entity)
	}

	//region   虚函数
	onStartGenData(entity : ConfigDataEntity){

	}

	onBeforeGenData(entity : ConfigDataEntity){

	}


	onAfterGenData(entity : ConfigDataEntity){

	}
	//endregion

	genData(entity : ConfigDataEntity){
	}
	//endregion


	//region  生成代码

	beforeGenCode(entity : ConfigDataEntity){
		this.onBeforeGenCode(entity)
	}

	afterGenCode(entity : ConfigDataEntity){
		this.onAfterGenCode(entity)
	}

	startGeCode(entity : ConfigDataEntity){
		this.onStartGeCode(entity)
	}



	genCode(entity : ConfigDataEntity){
	}

	genCodeEnd(){
		this.onGenCodeEnd()
	}

	genDataEnd(){
		this.onGenDataEnd()
	}

	//region   虚函数
	onStartGeCode(entity : ConfigDataEntity){

	}

	onBeforeGenCode(entity : ConfigDataEntity){

	}


	onAfterGenCode(entity : ConfigDataEntity){

	}

	onGenCodeEnd(){

	}

	onGenDataEnd(){

	}

	//endregion
	//endregion

	callListAction(list, entity, data = null){
		for (let i = 0; i < list.length; i++) {
			list[i](this, entity, data)
		}
	}

}
// let ejs = require('ejs')
// let file = fs.readFileSync("/Users/magictavern/NewGame/Tool/config-tool/src/excel/code_generater/ts/template/ConfigCenter.ejs", 'utf-8')
// console.log(file)
// let ret = ejs.render(file,{classNameList : ["asd", "sdgdfgdfg"]})
// console.log(ret)
